package com.anabur.bean;

import java.io.IOException;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import com.anabur.bean.abstracts.AbstractBean;

@ManagedBean(name="mainBean")
@SessionScoped
public class MainBean extends AbstractBean {

	private static final long serialVersionUID = 1L;

	public MainBean(){
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
		Map<String, Object> sessionMap = externalContext.getSessionMap();
		if(sessionMap.get(LOGGED_IN) == null
				|| !(Boolean)sessionMap.get(LOGGED_IN)){
			try {
				externalContext.redirect("login.xhtml");
			} catch (IOException e) {
				logErrorInPopupWithoutDetail(e);
			}
		} else {
			setUserLoggedname((String)sessionMap.get(USER_LOG_NAME));
		}
	}

}
